package zhtt.example.filter2;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class GatewayFilterConfig {

    @Bean
    public MyGlobalFilter myGlobalFilter() {
        return new MyGlobalFilter();
    }

    @Bean
    public MyPreFilter myPreFilter() {
        return new MyPreFilter();
    }

    @Bean
    public MyPostFilter myPostFilter() {
        return new MyPostFilter();
    }

    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
        // http://localhost:8020/api/header2
        return builder.routes()
                .route("route1", r -> r.path("/api/**")
                        .filters(f -> f.filter(myPreFilter()).filter(myPostFilter()).stripPrefix(1))
                        .uri("http://localhost:8040"))
                .build();
    }
}
